package logic

import (
	"context"
	"renting-demo/model/mysql"

	"renting-demo/house_srv/house"
	"renting-demo/house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic {
	return &CreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateLogic) Create(in *house.CreateHouseRequest) (*house.Response, error) {
	// todo: add your logic here and delete this line
	h := mysql.House{
		HouseSize:        float64(in.HouseSize),
		Text:             in.Text,
		HouseLocal:       in.HouseLocal,
		AddressId:        int(in.AddressId),
		Price:            float64(in.Price),
		CharacteristicId: int(in.CharacteristicId),
		Status:           1,
	}
	re := mysql.Create(h)
	if re == (mysql.House{}) {
		return &house.Response{
			Status: "0",
		}, nil
	}
	return &house.Response{
		Status: "1",
	}, nil
}
